<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the WriteResult for the failed write operation</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.mongodb-driver-exception-writeexception.html">« MongoDB\Driver\Exception\WriteException</a></li>
      <li style="float: right;"><a href="set.mysqlinfo.html">MySQL »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-driver-exception-writeexception.html">MongoDB\Driver\Exception\WriteException</a></li>
    <li>Returns the WriteResult for the failed write operation</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-driver-writeexception.getwriteresult" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\Exception\WriteException::getWriteResult</h1>
  <p class="verinfo">(mongodb &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Exception\WriteException::getWriteResult</span> &mdash; <span class="dc-title">Returns the WriteResult for the failed write operation</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-writeexception.getwriteresult-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\Exception\WriteException::getWriteResult</strong></span>(): <span class="type"><a href="class.mongodb-driver-writeresult.html" class="type MongoDB\Driver\WriteResult">MongoDB\Driver\WriteResult</a></span></div>

  <p class="para rdfs-comment">
   Returns the <span class="classname"><a href="class.mongodb-driver-writeresult.html" class="classname">MongoDB\Driver\WriteResult</a></span> for the failed
   write operation. The
   <span class="function"><a href="mongodb-driver-writeresult.getwriteerrors.html" class="function">MongoDB\Driver\WriteResult::getWriteErrors()</a></span> and
   <span class="function"><a href="mongodb-driver-writeresult.getwriteconcernerror.html" class="function">MongoDB\Driver\WriteResult::getWriteConcernError()</a></span> methods
   may be used to get more details about the failure.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-writeexception.getwriteresult-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-writeexception.getwriteresult-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The <span class="classname"><a href="class.mongodb-driver-writeresult.html" class="classname">MongoDB\Driver\WriteResult</a></span> for the failed write
   operation.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-mongodb-driver-writeexception.getwriteresult-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1403">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\Driver\Exception\WriteException::getWriteResult()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">'mongodb://localhost'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$bulk&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">BulkWrite</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bulk</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">([</span><span style="color: #DD0000">'_id'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$bulk</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">([</span><span style="color: #DD0000">'_id'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeBulkWrite</span><span style="color: #007700">(</span><span style="color: #DD0000">'db.collection'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bulk</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Exception</span><span style="color: #007700">\</span><span style="color: #0000BB">WriteException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$writeResult&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getWriteResult</span><span style="color: #007700">();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$writeConcernError&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$writeResult</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getWriteConcernError</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$writeConcernError</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$writeErrors&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$writeResult</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getWriteErrors</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$writeErrors</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(1) {
  [0]=&gt;
  object(MongoDB\Driver\WriteError)#5 (4) {
    [&quot;message&quot;]=&gt;
    string(70) &quot;E11000 duplicate key error index: db.collection.$_id_ dup key: { : 1 }&quot;
    [&quot;code&quot;]=&gt;
    int(11000)
    [&quot;index&quot;]=&gt;
    int(1)
    [&quot;info&quot;]=&gt;
    NULL
  }
}
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongodb-driver-writeexception.getwriteresult-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="classname"><a href="class.mongodb-driver-writeresult.html" class="classname">MongoDB\Driver\WriteResult</a></span></li>
   <li class="member"><span class="function"><a href="mongodb-driver-manager.executebulkwrite.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::executeBulkWrite()</a> - Execute one or more write operations</span></li>
  </ul>
 </div>


</div></div></div></body></html>